package com.ss.android.newmedia.feedback;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.ColorFilter;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.frameworks.baselib.network.http.util.TaskInfo;
import com.ss.android.article.browser.R;
import com.ss.android.common.app.LifeCycleMonitor;
import com.ss.android.image.AvatarLoader;
import com.ss.android.image.BaseImageManager;
import com.ss.android.image.loader.ImageLoader;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public final class h extends BaseAdapter implements LifeCycleMonitor, o {
    final List a;
    private final LayoutInflater b;
    private final SimpleDateFormat c;
    private final o m;
    private final int n;
    private final int o;
    private final int p;
    private final int q;
    private final int r;
    private final int s;
    private AvatarLoader d;
    private ImageLoader e;
    private TaskInfo f;
    private Context g;
    private ColorFilter h;
    private int i;
    private int j;
    private boolean k;
    private boolean l;

    public h(Context arg11, o arg12) {

        this.a = new ArrayList();
        this.j = 20000;
        this.k = true;
        this.l = false;
        this.b = LayoutInflater.from(arg11);
        this.c = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
        this.f = new TaskInfo();
        this.g = arg11;
        this.h = TTUtils.getNightModeColorFilter();
        this.m = arg12;
        Resources v8 = arg11.getResources();
        int v5 = v8.getDimensionPixelSize(R.dimen.el);
        this.d = new AvatarLoader(com.ss.android.article.browser.R.drawable.o2, this.f, new BaseImageManager(arg11), v5 << 1, v5, true);
        this.k = v8.getBoolean(R.bool.t);
        this.i = v8.getDisplayMetrics().widthPixels - v8.getDimensionPixelOffset(R.dimen.en);
        this.e = new ImageLoader(arg11, this.f, 4, 4, new BaseImageManager(arg11), this.i, this.j);
        this.n = v8.getColor(com.ss.android.article.browser.R.color.js);
        this.o = v8.getColor(com.ss.android.article.browser.R.color.je);
        this.p = v8.getColor(com.ss.android.article.browser.R.color.jt);
        this.q = v8.getColor(com.ss.android.article.browser.R.color.jf);
        this.r = v8.getDimensionPixelOffset(R.dimen.eo);
        this.s = v8.getDimensionPixelOffset(R.dimen.ep);
    }

    public final void a(String arg4, String arg5, Bitmap arg6) {
        Object v0_1 = null;
        Bitmap v0;
        if (this.l) {
            if (arg6 == null) {
                ImageLoader v1 = this.e;
                String v2 = com.bytedance.common.utility.aa.md5(arg4);
                v0 = null;
                if (v2 != null) {
                    v0_1 = v1.mLRUWeakCache.get(v2);
                }
            } else {
                v0_1 = arg6;
            }

            if (this.m == null) {
                return;
            }

            this.m.a(arg4, arg5, ((Bitmap) v0_1));
        }
    }

    public final void onDestroy() {
        if (this.d != null) {
            this.d.onDestroy();
        }

        if (this.e != null) {
            this.e.onDestroy();
        }

        if (this.f != null) {
            this.f.a = true;
        }
    }

    public final void onResume() {
        this.l = true;
        if (this.d != null) {
            this.d.onPause();
        }

        if (this.e != null) {
            this.e.onPause();
        }
    }

    public final void onPause() {
    }

    public final int getCount() {
        return this.a.size();
    }

    public final Object getItem(int arg2) {
        Object v0 = arg2 < 0 || arg2 >= this.a.size() ? null : this.a.get(arg2);
        return v0;
    }

    public final long getItemId(int arg3) {
        long v0 = arg3 < 0 || arg3 >= this.a.size() ? -1 : ((com.ss.android.newmedia.feedback.g) this.a.get(arg3)).a;
        return v0;
    }

    public final View getView(int arg10, View arg11, ViewGroup arg12) {
        int v1_3;
        a v7;
        if (arg11 == null) {
            a v1 = new a(((o) this));
            arg11 = this.b.inflate(com.ss.android.article.browser.R.layout.do0, null);
            v1.b = arg11.findViewById(com.ss.android.article.browser.R.id.v9);
            v1.a = arg11.findViewById(com.ss.android.article.browser.R.id.v2);
            v1.c = arg11.findViewById(com.ss.android.article.browser.R.id.v6);
            v1.d = arg11.findViewById(com.ss.android.article.browser.R.id.v5);
            v1.e = arg11.findViewById(com.ss.android.article.browser.R.id.v7);
            v1.f = arg11.findViewById(com.ss.android.article.browser.R.id.v4);
            v1.g = arg11.findViewById(com.ss.android.article.browser.R.id.v8);
            v1.h = arg11.findViewById(com.ss.android.article.browser.R.id.v3);
            v1.i = arg11.findViewById(com.ss.android.article.browser.R.id.v1);
            v1.j = arg11.findViewById(com.ss.android.article.browser.R.id.bottom_padding);
            arg11.setTag(v1);
            v7 = v1;
        } else {
            v7 = (com.ss.android.newmedia.feedback.h.a) arg11.getTag();
        }

        if (arg10 == 0) {
            v7.i.setVisibility(View.VISIBLE);
        } else {
            v7.i.setVisibility(View.GONE);
        }

        if (arg10 == this.a.size() - 1) {
            v7.j.setVisibility(View.VISIBLE);
        } else {
            v7.j.setVisibility(View.GONE);
        }

        Object v0 = this.a.get(arg10);
        v7.k = ((g) v0);
        if (v7.c != null) {
            v7.c.setOnClickListener(v7.n);
        }

        if (((g) v0).j == null || ((g) v0).j.size() <= 0 || (android.support.design.a.isTextEmpty(((g) v0).c))) {
            v7.d.setText(((g) v0).c);
        } else {
            SpannableString v3 = new SpannableString(((g) v0).c);
            int v4 = ((g) v0).j.size();
            int v2;
            for (v2 = 0; v2 < v4; ++v2) {
                Object v1_1 = ((g) v0).j.get(v2);
                v3.setSpan(new l(((com.ss.android.newmedia.feedback.g.a) v1_1).c), ((com.ss.android.newmedia.feedback.g.a) v1_1).a, ((com.ss.android.newmedia.feedback.g.a) v1_1).b + ((com.ss.android.newmedia.feedback.g.a) v1_1).a, 34);
            }

            v7.d.setText(((CharSequence) v3));
            v7.d.setMovementMethod(LinkMovementMethod.getInstance());
        }

        if (((g) v0).b <= 0) {
            v7.e.setVisibility(View.GONE);
        } else {
            v7.e.setVisibility(View.VISIBLE);
            v7.e.setText(this.c.format(new Date(((g) v0).b * 1000)));
        }

        ViewGroup.LayoutParams v1_2 = v7.e.getLayoutParams();
        ViewGroup.LayoutParams v2_1 = v7.f.getLayoutParams();
        ViewGroup.LayoutParams v3_1 = v7.d.getLayoutParams();
        ViewGroup.LayoutParams v4_1 = v7.c.getLayoutParams();
        int v5 = v7.l ? this.p : this.n;
        int v6 = v7.l ? this.q : this.o;
        if (((g) v0).h == 0) {
            com.ss.android.j.b.isNightModeToggled();
            v7.f.setBackgroundResource(com.ss.android.article.browser.R.drawable.ox);
            v7.f.setGravity(5);
            v7.b.setVisibility(View.VISIBLE);
            v7.a.setVisibility(View.INVISIBLE);
            v7.d.setTextColor(v5);
            v7.e.setTextColor(v5);
            if (this.d != null) {
                this.d.loadAvatar(v7.b, ((g) v0).e);
            }

            v7.g.setVisibility(View.GONE);
            v7.h.setVisibility(View.VISIBLE);
            if (v1_2 != null) {
                ((LinearLayout.LayoutParams) v1_2).gravity = 5;
            }

            if (v3_1 != null) {
                ((LinearLayout.LayoutParams) v3_1).leftMargin = this.s;
                ((LinearLayout.LayoutParams) v3_1).rightMargin = this.r;
            }

            if (v4_1 != null) {
                ((LinearLayout.LayoutParams) v4_1).leftMargin = this.s;
                ((LinearLayout.LayoutParams) v4_1).rightMargin = this.r;
            }

            if (v2_1 == null) {
            } else {
                ((LinearLayout.LayoutParams) v2_1).gravity = 5;
            }
        } else {
            com.ss.android.j.b.isNightModeToggled();
            v7.f.setBackgroundResource(com.ss.android.article.browser.R.drawable.oy);
            v7.f.setGravity(3);
            v7.b.setVisibility(View.INVISIBLE);
            v7.a.setVisibility(View.VISIBLE);
            v7.d.setTextColor(v6);
            v7.e.setTextColor(v6);
            v7.a.setImageResource(com.ss.android.article.browser.R.drawable.ee);
            if (this.d != null) {
                this.d.loadAvatar(v7.a, ((g) v0).e);
            }

            v7.g.setVisibility(View.VISIBLE);
            v7.h.setVisibility(View.GONE);
            if (v1_2 != null) {
                ((LinearLayout.LayoutParams) v1_2).gravity = 3;
            }

            if (v3_1 != null) {
                ((LinearLayout.LayoutParams) v3_1).leftMargin = this.r;
                ((LinearLayout.LayoutParams) v3_1).rightMargin = this.s;
            }

            if (v4_1 != null) {
                ((LinearLayout.LayoutParams) v4_1).leftMargin = this.r;
                ((LinearLayout.LayoutParams) v4_1).rightMargin = this.s;
            }

            if (v2_1 == null) {
            } else {
                ((LinearLayout.LayoutParams) v2_1).gravity = 3;
            }
        }

        v7.f.requestLayout();
        if ((android.support.design.a.isTextEmpty(((g) v0).d)) || ((g) v0).f <= 0 || ((g) v0).g <= 0) {
            v7.c.setVisibility(View.GONE);
        } else {
            v7.c.setVisibility(View.VISIBLE);
            v1_3 = this.i * ((g) v0).g / ((g) v0).f;
            v2_1 = v7.c.getLayoutParams();
            v2_1.height = v1_3;
            v2_1.width = this.i;
            v7.c.setLayoutParams(v2_1);
            com.ss.android.j.b.isNightModeToggled();
            v7.c.setImageResource(com.ss.android.article.browser.R.drawable.cn);
            this.e.a(v7.c, ((g) v0).d, null);
        }

        if (v7.l != com.ss.android.j.b.isNightModeToggled() && (this.k)) {
            v7.l = com.ss.android.j.b.isNightModeToggled();
            Resources v3_2 = this.g.getResources();
            int v0_1 = v7.l ? R.color.jf : R.color.je;
            v1_3 = v7.l ? R.color.jn : R.color.jm;
            ColorFilter v2_2 = v7.l ? this.h : null;
            v7.d.setTextColor(v3_2.getColor(v0_1));
            v7.e.setTextColor(v3_2.getColor(v1_3));
            v7.a.setColorFilter(v2_2);
            v7.b.setColorFilter(v2_2);
        }

        return arg11;
    }

    public final void onStop() {
        this.l = false;
        if (this.d != null) {
            this.d.onStop();
        }

        if (this.e != null) {
            this.e.onStop();
        }
    }

    public final class a {
        final o m;
        final View.OnClickListener n;
        public ImageView a;
        public ImageView b;
        public ImageView c;
        public TextView d;
        public TextView e;
        public LinearLayout f;
        public View g;
        public View h;
        public View i;
        public View j;
        public g k;
        public boolean l;

        public a(o arg2) {

            this.l = false;
            this.n = new i(this);
            this.m = arg2;
        }
    }
}

